package com.jz.banner.screen.banner.utils;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.jz.banner.screen.ui.App;

public class AppUtils {
    /**
     * 获取应用程序名称
     */

    public static synchronized String getAppName() {

        try {

            PackageManager packageManager = App.Companion.getContext().getPackageManager();

            PackageInfo packageInfo = packageManager.getPackageInfo(

                    App.Companion.getContext().getPackageName(), 0);

            int labelRes = packageInfo.applicationInfo.labelRes;

            return App.Companion.getContext().getResources().getString(labelRes);

        } catch (Exception e) {

            e.printStackTrace();

        }

        return null;

    }


    /**
     * [获取应用程序版本名称信息]
     *
     * @return 当前应用的版本名称
     */

    public static synchronized String getVersionName() {

        try {

            PackageManager packageManager = App.Companion.getContext().getPackageManager();

            PackageInfo packageInfo = packageManager.getPackageInfo(

                    App.Companion.getContext().getPackageName(), 0);

            return packageInfo.versionName;

        } catch (Exception e) {

            e.printStackTrace();

        }

        return null;

    }


    /**
     * [获取应用程序版本名称信息]
     *
     * @return 当前应用的版本名称
     */

    public static synchronized int getVersionCode() {

        try {

            PackageManager packageManager = App.Companion.getContext().getPackageManager();

            PackageInfo packageInfo = packageManager.getPackageInfo(

                    App.Companion.getContext().getPackageName(), 0);

            return packageInfo.versionCode;

        } catch (Exception e) {

            e.printStackTrace();

        }

        return 0;

    }


    /**
     * [获取应用程序版本名称信息]
     *
     * @return 当前应用的版本名称
     */

    public static synchronized String getPackageName() {

        try {

            PackageManager packageManager = App.Companion.getContext().getPackageManager();

            PackageInfo packageInfo = packageManager.getPackageInfo(

                    App.Companion.getContext().getPackageName(), 0);

            return packageInfo.packageName;

        } catch (Exception e) {

            e.printStackTrace();

        }

        return null;

    }

}
